package com.ruoyi.ipms_patent.service.impl;

//import com.ruoyi.ipms_patent.entity.Inventor;
import com.ruoyi.common.core.constant.Constants;
import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.common.core.utils.IPMSUtils;
import com.ruoyi.common.security.utils.SecurityUtils;
import com.ruoyi.ipms_patent.entity.Patent;
import com.ruoyi.ipms_patent.mapper.InventorMapper;
import com.ruoyi.ipms_patent.mapper.PatentMapper;
import com.ruoyi.ipms_patent.service.InventorService;
import com.ruoyi.ipms_patent.service.PatentService;
import com.ruoyi.system.api.entity.Inventor;
import com.ruoyi.system.api.model.LoginUser;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/*专利业务实现类*/
@Service
public class PatentServiceImpl implements PatentService {

    @Resource
    private PatentMapper mapper;

    @Override
    public Patent addPatent(Patent patent) {

        LoginUser loginUser= SecurityUtils.getLoginUser();
        //创建人
        patent.setCreateBy(loginUser.getSysUser().getNickName());
        //创建时间
        patent.setCreateTime(DateUtils.getNowDate());
        //乐观锁
        patent.setVersion(Constants.VERSION_LOCK);
        //逻辑删除
        patent.setIsDelete(Constants.IS_DELETED);
        //更新人
        patent.setUpdateBy(loginUser.getSysUser().getNickName());
        //更新时间
        patent.setUpdateTime(DateUtils.getNowDate());
        //专利编号
        patent.setPatendNo(IPMSUtils.spawnNo("PATENT.", 5));
        int result = mapper.insertOne(patent);
        return result > 0 ? patent : null;
    }

    @Override
    public List<Patent> findPatentList(Integer customerId) {
        return mapper.selectList(customerId);
    }

    /* 修改专利材料地址 */
    @Override
    public int updatePatent(Patent patent) {
        return mapper.updatePatent(patent);
    }
}
